﻿/*
 *Debug_Tr.c
 *
 *Created on:2022-01-26 05:33:35
 *
 *Author:By BMS Developer Team
 *
 *ToolVersion: V1.0.0.9
*/


/******************************************************************************/
/*----------------------------------Includes----------------------------------*/
/******************************************************************************/
#include "includes.h"

/******************************************************************************/
/*-------------------------Function Implementations---------------------------*/
/******************************************************************************/
//Pack
void CAN0_Send_0x6C2_Debug_HVPara(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)((uint16_T)gwPackVoltageCorrectACoef);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);


	tempData = (uint32_T)((uint16_T)gwLinkVoltageCorrectACoef);
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	tempData = (uint32_T)((uint16_T)gwPTCVoltageCorrectACoef);
	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
	Data[5] = Data[5] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x02,Data,8);  //Enqueue
}

void CAN0_Send_0x6C3_Debug_ExDflash(void)
{
	uint32_T tempData;
	uint64_t temp;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	#if Bccfg_BCU_ExDflashUseType

	tempData = (uint16_T)(ExDflash_WR_PageOffsetADD);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);

	tempData = (uint16_T)(ExDflash_RD_PageOffsetADD);
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	temp = (uint32_t)(Ex_Dflash_DebugID);//0xC84017
	Data[4] = Data[4] | (uint8_T)(temp >> 16);
	Data[5] = Data[5] | (uint8_T)(temp >> 8);
	Data[6] = Data[6] | (uint8_T)(temp>>0);
	Data[7] = Data[7] | (uint8_T)((ExDflash_NOR_ChipEraseLockFlag) & 0x1);
	Data[7] = Data[7] | (uint8_T)(((BMS_DatRecordReadSelfLockFlag) & 0x1) << 1);
	Data[7] = Data[7] | (uint8_T)(((ExDflash_NOR_DebugID_EN_Flag) & 0x1) << 2);
	Data[7] = Data[7] | (uint8_T)(((ExDflash_NOR_DebugID_EN_Flag) & 0x1) << 3);
	#endif

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x03,Data,8);  //Enqueue
}

void CAN0_Send_0x6C4_Debug_IOSts(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	Data[0] = Data[0] | (uint8_T)((rte_flg_rlyPosSts_GetVal()     		) & 0x1);
	Data[0] = Data[0] | (uint8_T)(((bottv_flg_posRlyCtrl	     		) & 0x1) << 1);
	Data[0] = Data[0] | (uint8_T)(((rte_flg_rlyNegSts_GetVal()    		) & 0x1) << 2);
	Data[0] = Data[0] | (uint8_T)(((bottv_flg_negRlyCtrl          		) & 0x1) << 3);
	Data[0] = Data[0] | (uint8_T)(((rte_flg_rlyPreSts_GetVal() 		    ) & 0x1) << 4);
	Data[0] = Data[0] | (uint8_T)(((bottv_flg_PrechgRlyCtrl       		) & 0x1) << 5);
	Data[0] = Data[0] | (uint8_T)(((rte_flg_rlyPTCSts_GetVal()    		) & 0x1) << 6);
	Data[0] = Data[0] | (uint8_T)(((bottv_flg_heatRlyCtrl         		) & 0x1) << 7);

	Data[1] = Data[1] | (uint8_T)((rte_flg_heatNegRlySts_GetVal()  ) & 0x1);
	Data[1] = Data[1] | (uint8_T)(((/*bottv_flg_heatRlyCtrl*/0	    	) & 0x1) << 1);
	Data[1] = Data[1] | (uint8_T)(((rte_flg_fastPosRly1Status_GetVal()	) & 0x1) << 2);
	Data[1] = Data[1] | (uint8_T)(((bottv_flg_fastChgRlyCtrl			) & 0x1) << 3);
	Data[1] = Data[1] | (uint8_T)(((rte_flg_fastNegRly1Status_GetVal()	) & 0x1) << 4);
	Data[1] = Data[1] | (uint8_T)(((/*vewm_flg_qchgNegRlyCtr*/0			) & 0x1	)<< 5);
	Data[1] = Data[1] | (uint8_T)(((rte_flg_fastPosRly2Status_GetVal()	) & 0x1) << 6);
	Data[1] = Data[1] | (uint8_T)(((/*vewm_flg_qchgPosRly2Ctr*/0		) & 0x1) << 7);

	Data[2] = Data[2] | (uint8_T)((rte_flg_fastNegRly2Status_GetVal()	) & 0x1);
	Data[2] = Data[2] | (uint8_T)(((/*vewm_flg_qchgNegRly2Ctr*/0		) & 0x1) << 1);
	Data[2] = Data[2] | (uint8_T)(((rte_flg_WaterRlyStatus_GetVal()		) & 0x1) << 2);
	Data[2] = Data[2] | (uint8_T)(((/*tmsc_flg_waterRlyCtr*/0			) & 0x1) << 3);
	Data[2] = Data[2] | (uint8_T)(((rte_flg_bmu1CtrlStatus_GetVal()		) & 0x1) << 4);
	Data[2] = Data[2] | (uint8_T)(((rte_flg_bmu2CtrlStatus_GetVal()		) & 0x1) << 5);
	Data[2] = Data[2] | (uint8_T)(((rte_flg_rlyPowerSts_GetVal()		) & 0x1) << 6);
	Data[2] = Data[2] | (uint8_T)(((bottv_flg_ignition					) & 0x1) << 7);

	Data[3] = Data[3] | (uint8_T)((rte_flg_keyonSts_GetVal()			) & 0x1);
	Data[3] = Data[3] | (uint8_T)(((Rte_flg_SChgIgSts_GetVal()			) & 0x1) << 1);
	Data[3] = Data[3] | (uint8_T)(((Rte_flg_QChgIgSts_GetVal()			) & 0x1) << 2);
	Data[3] = Data[3] | (uint8_T)(((rte_flg_qchgIg2Sts_GetVal()			) & 0x1) << 3);
	Data[3] = Data[3] | (uint8_T)(((rte_flg_finIgSts_GetVal()			) & 0x1) << 4);
	Data[3] = Data[3] | (uint8_T)(((rte_flg_igKeepSts_GetVal()			) & 0x1) << 5);
	Data[3] = Data[3] | (uint8_T)(((rte_flg_canWakeUpSts_GetVal()		) & 0x1) << 6);
	Data[3] = Data[3] | (uint8_T)(((rte_flg_cpWakeUpSts_GetVal()		) & 0x1) << 7);

	Data[4] = Data[4] | (uint8_T)((rte_flg_ccWakeUpSts_GetVal()			) & 0x1);
	Data[4] = Data[4] | (uint8_T)(((rte_enum_schgCcSts_GetVal()			) & 0x1) << 1);
	Data[4] = Data[4] | (uint8_T)(((rte_flg_qchgCC2_GetVal()			) & 0x1) << 2);
	Data[4] = Data[4] | (uint8_T)(((rte_flg_qchg2CC2_GetVal()			) & 0x1) << 3);

	Data[5] = Data[5] | (uint8_T)((0) & 0xF);
	Data[5] = Data[5] | (uint8_T)(((0) & 0xF) << 4);

	Data[6] = Data[6] | (uint8_T)((0) & 0xF);
	Data[6] = Data[6] | (uint8_T)(((/*Debug_DCCharger2SubState*/0) & 0xF) << 4);

	Data[7] = Data[7] | 0;//(uint8_T)(rte_pct_schgCP_GetVal());
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x04,Data,8);  //Enqueue
}

void CAN0_Send_0x6C5_Debug_ChgReqCurr(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

//	tempData = (uint32_T)(sopv_a_chgReqCur);
//	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
//	Data[1] = Data[1] | (uint8_T)(tempData);
//
//	tempData = (uint32_T)(sopv_a_chgReqCur);
//	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
//	Data[3] = Data[3] | (uint8_T)(tempData);
//
//	tempData = (uint32_T)(sopv_v_chgReqVol);
//	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
//	Data[5] = Data[5] | (uint8_T)(tempData);

//	tempData = (uint32_T)(sopv_a_heatReqCurr);
//	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
//	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x05,Data,8);  //Enqueue
}

void CAN0_Send_0x6C6_Debug_SOHInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)(bottv_as_soh);
	Data[0] = Data[0] | (uint8_T)(tempData >> 24);
	Data[1] = Data[1] | (uint8_T)(tempData >> 16);
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	tempData = (uint32_T)(sohe_pct_soh);
	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
	Data[5] = Data[5] | (uint8_T)(tempData);

	tempData = (uint32_T)(bottv_as_Cycle);
	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x06,Data,8);  //Enqueue
}

void CAN0_Send_0x6C7_Debug_Add(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)(Rte_TAB_mas_Nmcpv_GetVal());//(soce_mas_nomAh);//(Pccfg_NormBattCap);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);

	tempData = (uint32_T)(rte_mv_cellVolAvg_GetVal());
	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
	Data[5] = Data[5] | (uint8_T)(tempData);

	tempData = (uint32_T)(soce_pct_SOC);
	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x07,Data,8);  //Enqueue
}

void CAN0_Send_0x6C8_Debug_Soh(void)
{
    stCAN_SWObj    FrameObj;
    uint8_t i=0;
    static uint8_t numFact=0U,numCycle=0U;

    if(bottv_flg_upLoadSOH==1U)
    {
    	if(numFact<5)
    	{
			FrameObj.ulID.ulVal	=	CAN_0x6C0_TXID|0x08;
			FrameObj.ubLen  = 8 ;
			FrameObj.ubData[0]	 =   0x10+numFact;
			for(i=0;i<3U;i++)
			{
			   FrameObj.ubData[i*2+1]= (uint8_t)(soh_fact[numFact*3U+i]>>8U);
			   FrameObj.ubData[i*2+2]= (uint8_t)soh_fact[numFact*3U+i];
			}
			FrameObj.ubData[7]	 =   0x11;
			VCUCAN_Debug_Send_Data(FrameObj.ulID.ulVal,FrameObj.ubData,8);
    	}
        if(++numFact>=6)
        {
            numFact=0U;
            bottv_flg_upLoadSOH=2;
        }
    }
    if(bottv_flg_upLoadSOH==2U)
    {
        FrameObj.ulID.ulVal	=	CAN_0x6C0_TXID|0x08; ;
        FrameObj.ubLen  = 8 ;
        FrameObj.ubData[0]	 =   0x20+numCycle;
        for(i=0;i<3U;i++)
        {
           FrameObj.ubData[i*2+1]= (uint8_t)(soh_total[numCycle*3U+i]>>8U);
           FrameObj.ubData[i*2+2]= (uint8_t)soh_total[numCycle*3U+i];
        }
        FrameObj.ubData[7]	 =   0x22;
        if(++numCycle>=5)
        {
            bottv_flg_upLoadSOH=0U;
            numCycle=0U;
        }
        VCUCAN_Debug_Send_Data(FrameObj.ulID.ulVal,FrameObj.ubData,8);
    }
}

void CAN0_Send_0x6C9_Debug_HVInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	static uint8_T serialmun=0;

	tempData = (uint16_T)(++serialmun);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);


	if(serialmun==1)
	{
		tempData = (uint32_T)((rte_mv_packVol_GetVal()+50)/100);
		Data[2] = Data[2] | (uint8_T)(tempData >> 8);
		Data[3] = Data[3] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_linkVol_GetVal()+50)/100);
		Data[4] = Data[4] | (uint8_T)(tempData >> 8);
		Data[5] = Data[5] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_lpVol_GetVal()+50)/100);
		Data[6] = Data[6] | (uint8_T)(tempData >> 8);
		Data[7] = Data[7] | (uint8_T)(tempData);
	}


	else if(serialmun==2)
	{
//		tempData = (uint32_T)((rte_mv_plVol_GetVal()+50)/100);
		Data[2] = Data[2] | (uint8_T)(tempData >> 8);
		Data[3] = Data[3] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_ptcVol_GetVal()+50)/100);
		Data[4] = Data[4] | (uint8_T)(tempData >> 8);
		Data[5] = Data[5] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_hpVol_GetVal()+50)/100);
		Data[6] = Data[6] | (uint8_T)(tempData >> 8);
		Data[7] = Data[7] | (uint8_T)(tempData);
	}

	else if(serialmun==3)
	{
		tempData = (uint32_T)((rte_mv_phVol_GetVal()+50)/100);
		Data[2] = Data[2] | (uint8_T)(tempData >> 8);
		Data[3] = Data[3] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_qchg1Vol_GetVal()+50)/100);
		Data[4] = Data[4] | (uint8_T)(tempData >> 8);
		Data[5] = Data[5] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_qchg2Vol_GetVal()+50)/100);
		Data[6] = Data[6] | (uint8_T)(tempData >> 8);
		Data[7] = Data[7] | (uint8_T)(tempData);
	}


	else if(serialmun==4)
	{
		tempData = (uint32_T)((rte_mv_qp1Vol_GetVal()+50)/100);
		Data[2] = Data[2] | (uint8_T)(tempData >> 8);
		Data[3] = Data[3] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_qp2Vol_GetVal()+50)/100);
		Data[4] = Data[4] | (uint8_T)(tempData >> 8);
		Data[5] = Data[5] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_pq1Vol_GetVal()+50)/100);
		Data[6] = Data[6] | (uint8_T)(tempData >> 8);
		Data[7] = Data[7] | (uint8_T)(tempData);
	}

	else if(serialmun==5)
	{
		tempData = (uint32_T)((rte_mv_pq2Vol_GetVal()+50)/100);
		Data[2] = Data[2] | (uint8_T)(tempData >> 8);
		Data[3] = Data[3] | (uint8_T)(tempData);

		tempData = (uint32_T)((rte_mv_waterVol_GetVal()+50)/100);
		Data[4] = Data[4] | (uint8_T)(tempData >> 8);
		Data[5] = Data[5] | (uint8_T)(tempData);
		Data[6] = Data[6] | (uint8_T)(0 >> 8);
		Data[7] = Data[7] | (uint8_T)(0);
		serialmun=0;
	}
	else
	{
		;
	}

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x09,Data,8);  //Enqueue
}

void CAN0_Send_0x6CA_Debug_Ver(void)
{
    stCAN_SWObj    FrameObj;
    uint8_t j=0;
    uint8_t numb;
    static uint8_t batcode_num=0;
    	if(Test_flg_vcanTxRev)
		{
			if(Test_flg_vcanTxRev<=3)
			{
				FrameObj.ulID.ulVal	=	CAN_0x6C0_TXID|0x0A;;
				FrameObj.ubLen  = 8 ;

				FrameObj.ubData[0]  =  0xA0+Test_flg_vcanTxRev-1;
				for(j=1; j<8; j++)
				{
				   if(bottv_flg_debug)
				   {
					  FrameObj.ubData[j]  =  BMS_Hardware_Version_Number_Default[7*(Test_flg_vcanTxRev-1)+j-1];
				   }
				   else
				   {
					  FrameObj.ubData[j]  =  BMS_Hardware_Version_Number[7*(Test_flg_vcanTxRev-1)+j-1];
				   }
				}
				VCUCAN_Debug_Send_Data(FrameObj.ulID.ulVal,FrameObj.ubData,8);
			}
			else if(Test_flg_vcanTxRev<=8)
			{
				FrameObj.ulID.ulVal	=	CAN_0x6C0_TXID|0x0A;
				FrameObj.ubLen  = 8 ;

				FrameObj.ubData[0]  =  0xB0+Test_flg_vcanTxRev-4;
				for(j=1; j<8; j++)
				{
					if(bottv_flg_debug)
					{
						 FrameObj.ubData[j]  =  BMS_Software_Version_Number_Default[7*(Test_flg_vcanTxRev-4)+j-1];
					}
					else
					{
						 FrameObj.ubData[j]  =  BMS_Software_Version_Number[7*(Test_flg_vcanTxRev-4)+j-1];
					}
				}
				VCUCAN_Debug_Send_Data(FrameObj.ulID.ulVal,FrameObj.ubData,8);
			}
			else
			{
				FrameObj.ulID.ulVal	=	CAN_0x6C0_TXID|0x0A;
				FrameObj.ubLen  = 8 ;

				FrameObj.ubData[0]  =  0xD0+Test_flg_vcanTxRev-9;
				for(j=1; j<8; j++)
				{
					FrameObj.ubData[j]  =  BMS_Pcb_Version_Number_Default[7*(Test_flg_vcanTxRev-9)+j-1];
				}
				VCUCAN_Debug_Send_Data(FrameObj.ulID.ulVal,FrameObj.ubData,8);
			}

			if(Test_flg_vcanTxRev<10)
			{
				Test_flg_vcanTxRev++;
			}
			else
			{
				Test_flg_vcanTxRev=0;
			}
		}

        if(Test_num_icanTXRevTimout>0)
        	Test_num_icanTXRevTimout--;

        if(batcode_flg == 1)
		{
        	//batcode_num ++;

            switch(batcode_num++)
            {
				case 1:

					FrameObj.ulID.ulVal        =        0x750;//IDE,(DIR=TX)DATA Frame,8Data Length code
					FrameObj.ubLen  = 8 ;
					FrameObj.ubData[0]         =   BMS_Battery_Code[0];//BMS_11_550_DATA1;
					FrameObj.ubData[1]         =   BMS_Battery_Code[1];//BMS_11_550_DATA2;
					FrameObj.ubData[2]         =   BMS_Battery_Code[2];//BMS_11_550_DATA3;
					FrameObj.ubData[3]         =   BMS_Battery_Code[3];////(BMS_Battery_Code[3]&0x03)|((BMS_Battery_Code[4]&0x07)<<2);//BMS_11_550_DATA4;
					FrameObj.ubData[4]         =   BMS_Battery_Code[4];//BMS_11_550_DATA5;
					FrameObj.ubData[5]         =   BMS_Battery_Code[5];//BMS_11_550_DATA6;
					FrameObj.ubData[6]         =   BMS_Battery_Code[6];//BMS_11_550_DATA7;
					FrameObj.ubData[7]         =   BMS_Battery_Code[7];//BMS_11_550_DATA8;
				Debug_Send_Frame(&FrameObj);


				break;

				case 2:

					FrameObj.ulID.ulVal        =        0x755;//IDE,(DIR=TX)DATA Frame,8Data Length code
					FrameObj.ubLen  = 8 ;
					FrameObj.ubData[0]         =   BMS_Battery_Code[8];//BMS_12_555_DATA1;
					FrameObj.ubData[1]         =   BMS_Battery_Code[9];//BMS_12_555_DATA2;
					FrameObj.ubData[2]         =   BMS_Battery_Code[10];//BMS_12_555_DATA3;
					FrameObj.ubData[3]         =   BMS_Battery_Code[11];//BMS_12_555_DATA4;
					FrameObj.ubData[4]         =   BMS_Battery_Code[12];// BMS_12_555_DATA5;
					FrameObj.ubData[5]         =   BMS_Battery_Code[13];// BMS_12_555_DATA6;
					FrameObj.ubData[6]         =   BMS_Battery_Code[14];//BMS_12_555_DATA7;
					FrameObj.ubData[7]         =   BMS_Battery_Code[15];//BMS_12_555_DATA8;
					Debug_Send_Frame(&FrameObj);

				break;


				case 3:

						FrameObj.ulID.ulVal        =        0x75A;//IDE,(DIR=TX)DATA Frame,8Data Length code
						FrameObj.ubLen  = 8 ;
						FrameObj.ubData[0]         =   BMS_Battery_Code[16];//BMS_12_555_DATA1;
						FrameObj.ubData[1]         =   BMS_Battery_Code[17];//BMS_12_555_DATA2;
						FrameObj.ubData[2]         =   BMS_Battery_Code[18];//BMS_12_555_DATA3;
						FrameObj.ubData[3]         =   BMS_Battery_Code[19];//BMS_12_555_DATA4;
						FrameObj.ubData[4]         =   BMS_Battery_Code[20];// BMS_12_555_DATA5;
						FrameObj.ubData[5]         =   BMS_Battery_Code[21];// BMS_12_555_DATA6;
						FrameObj.ubData[6]         =   BMS_Battery_Code[22];//BMS_12_555_DATA7;
						FrameObj.ubData[7]         =   BMS_Battery_Code[23];//BMS_12_555_DATA8;
					Debug_Send_Frame(&FrameObj);
					batcode_flg=0;
					batcode_num=0;

				break;

				default:
				break;
            }
		}
}

void CAN0_Send_0x6CB_Debug_CellVoltInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	Data[0] = (uint8_T)(rte_no_cellVolMax_GetVal());
	Data[1] = (uint8_T)(rte_no_cellVolMin_GetVal());

	tempData = (uint32_T)(rte_mv_cellVolMax_GetVal());
	Data[2] =  (uint8_T)(tempData >> 8);
	Data[3] =  (uint8_T)(tempData);

	tempData = (uint32_T)(rte_mv_cellVolMin_GetVal());
	Data[4] =  (uint8_T)(tempData >> 8);
	Data[5] =  (uint8_T)(tempData);

	tempData = (uint32_T)((rte_mv_cellVolSum_GetVal()+5)/10);
	Data[6] =  (uint8_T)(tempData >> 8);
	Data[7] =  (uint8_T)(tempData);

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x0B,Data,8);  //Enqueue
}

void CAN0_Send_0x6CC_Debug_CellTempInfo(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =  (uint8_T)(rte_c_cellTmpMax_GetVal());
	Data[1] =  (uint8_T)(rte_c_cellTmpMin_GetVal());

	Data[2] =  (uint8_T)(rte_c_cellTmpAvg_GetVal());

	Data[3] =  (uint8_T)(rte_no_cellTmpMax_GetVal());
	Data[4] =  (uint8_T)(rte_no_cellTmpMin_GetVal());

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x0C,Data,8);  //Enqueue
}

void CAN0_Send_0x6CD_Debug_SmpVolt(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)(bottv_mv_SccVolt);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);

	tempData = (uint32_T)(bottv_mv_QccVolt);
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	tempData = (uint32_T)(bottv_mv_h12V);
	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
	Data[5] = Data[5] | (uint8_T)(tempData);

	tempData = (uint32_T)(rte_mv_splyPwrVol_GetVal());
	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
	Data[7] = Data[7] | (uint8_T)(tempData);

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x0d,Data,8);  //Enqueue
}
void CAN0_Send_0x6CE_Debug_SmpIg(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] = Data[0] | (uint8_T)((Rte_flg_QChgIgSts_GetVal()			) & 0x1);
	Data[0] = Data[0] | (uint8_T)(((Rte_flg_SChgIgSts_GetVal()			) & 0x1) << 1);
	Data[0] = Data[0] | (uint8_T)(((rte_flg_keyonSts_GetVal()			) & 0x1) << 2);
	Data[0] = Data[0] | (uint8_T)(((rte_flg_finIgSts_GetVal()			) & 0x1) << 4);

	tempData = (uint32_T)(rte_mv_cellVolAvg_GetVal());
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

//	tempData = (uint8_T)(rte_enum_CPDuty_GetVal());
//	Data[5] = Data[5] | (uint8_T)(tempData);

	//tempData = (uint32_T)(rte_mv_splyPwrVol_GetVal());
	Data[6] = Data[6] | (uint8_T)(soce_pct_SOC >> 8);
	Data[7] = Data[7] | (uint8_T)(soce_pct_SOC);

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x0e,Data,8);  //Enqueue
}

void CAN0_Send_0x6D0_Debug_RTC(void)
{
//	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	Data[0] = Data[0] | (uint8_T)0x20;
	Data[1] = Data[1] | (uint8_T)(RealTime.year);
	Data[2] = Data[2] | (uint8_T)(RealTime.month);
	Data[3] = Data[3] | (uint8_T)(RealTime.day);
	Data[4] = Data[4] | (uint8_T)(RealTime.hour);
	Data[5] = Data[5] | (uint8_T)(RealTime.minute);
	Data[6] = Data[6] | (uint8_T)(RealTime.second);
	Data[7] = Data[7] | (uint8_T)(RealTime.week);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x10,Data,8);  //Enqueue
}

void CAN0_Send_0x6D1_Debug_SOCInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)(bottv_pct_deltaSoc);//SOC下电存储偏差
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);

	tempData = (uint32_T)(currv_fact_k);//SOC修正系数K
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	tempData = (uint32_T)(soce_pct_deltaSoc);//SOC修正偏差
	Data[4] = Data[4] | (uint8_T)(tempData >> 8);
	Data[5] = Data[5] | (uint8_T)(tempData);

	tempData = (uint32_T)(soce_pct_RealSOC);//真实SOC
	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x11,Data,8);  //Enqueue
}

void CAN0_Send_0x6D2_Debug_CurrInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

//	tempData = (uint32_T)((uint16_T)(DEBUG_Tx_BatCurr1()));
//	Data[0] = Data[0] | (uint8_T)(tempData >> 8);//	总电流
//	Data[1] = Data[1] | (uint8_T)(tempData);

//	tempData = (uint32_T)((uint16_T)(bottv_ma_cur2/100));
//	Data[2] = Data[2] | (uint8_T)(tempData >> 8);//	电流传感器2电流
//	Data[3] = Data[3] | (uint8_T)(tempData);
//
//	tempData = (uint32_T)(bottv_mv_HallOffset0);
//	Data[4] = Data[4] | (uint8_T)(tempData >> 8);//	零点偏置电流
//	Data[5] = Data[5] | (uint8_T)(tempData);
//
//	tempData = (uint32_T)(bottv_mv_CurrVolt);//	电流模拟值
//	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
//	Data[7] = Data[7] | (uint8_T)(tempData);

//	tempData = ((uint32_T)DEBUG_Tx_BatCurr1());//(bottv_mv_AD_HALL1));
//	Data[2] = Data[2] | (uint8_T)(tempData >> 8);//	电流传感器2电流
//	Data[3] = Data[3] | (uint8_T)(tempData);
//
//	tempData = ((uint32_T)DEBUG_Tx_BatCurr2());//(bottv_mv_AD_HALL2));
//	Data[4] = Data[4] | (uint8_T)(tempData >> 8);//	零点偏置电流
//	Data[5] = Data[5] | (uint8_T)(tempData);

//	tempData = ((uint16_T)(mc33771_k_curr/100));//	电流模拟值
//	tempData = ((uint32_T)DEBUG_Tx_BatCurr3());//(bottv_mv_AD_HALL2));
//	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
//	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x12,Data,8);  //Enqueue
}

void CAN0_Send_0x6D3_Debug_WorkModeInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] = Data[0] | (uint8_T)((vewm_enum_workingMode) & 0xF);
	Data[0] = Data[0] | (uint8_T)(((vewm_enum_DisSts) & 0xF) << 4);
	Data[1] = Data[1] | (uint8_T)((vewm_enum_SlowChgSts) & 0xF);
	Data[1] = Data[1] | (uint8_T)(((vewm_enum_FastChgSts) & 0xF) << 4);
	Data[2] = Data[2] | (uint8_T)((tmsc_enum_HeatSts) & 0xF);
	Data[4] = Data[4] | (uint8_T)(balc_flg_balanceEn);
	Data[5] = Data[5] | (uint8_T)(bottv_num_cellov);

	tempData = (uint32_T)(balc_mv_balOpenCVlt);
	Data[6] = Data[6] | (uint8_T)(tempData >> 8);
	Data[7] = Data[7] | (uint8_T)(tempData);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x13,Data,8);  //Enqueue
}

void CAN0_Send_0x6D4_Debug_Info(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =  (uint8_t)(bottc_ko_SccResist/256);
	Data[1] =  (uint8_t)(bottc_ko_SccResist%256);
	Data[2] =  (uint8_t)(bottc_ko_QccResist/256);
	Data[3] =  (uint8_t)(bottc_ko_QccResist%256);

	Data[4] =  (uint8_T)(bottv_k_cpFreq/256);
	Data[5] =  (uint8_T)(bottv_k_cpFreq%256);


	Data[6] = Data[6] |   0;
	Data[7] = Data[7] | (uint8_T)(rte_pct_schgCP_GetVal());
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x14,Data,8);  //Enqueue
}

void CAN0_Send_0x6D6_Debug_InsInfo(void)
{
	uint32_T tempData;
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	tempData = (uint32_T)(bottv_ohm_isoRpRes);
	Data[0] = Data[0] | (uint8_T)(tempData >> 8);
	Data[1] = Data[1] | (uint8_T)(tempData);

	tempData = (uint32_T)(bottv_ohm_isoRnRes);
	Data[2] = Data[2] | (uint8_T)(tempData >> 8);
	Data[3] = Data[3] | (uint8_T)(tempData);

	Data[4] = Data[4] | (uint8_T)(bottv_flg_InsuCtlOff);

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x16,Data,8);  //Enqueue
}

void CAN0_Send_0x6D7_Debug_FaultInfo(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	Data[0] = Data[0] | (uint8_T)(fltm_num_maxFltNo);
	Data[3] = Data[3] | (uint8_T)(fltm_enum_dsgFltLv);
	Data[4] = Data[4] | (uint8_T)(fltm_enum_chgFltLv);
	Data[2] = Data[2] | (uint8_T)(fltm_enum_FltNum);
	Data[1] = Data[1] | (uint8_T)(Rte_CANTx_FltCode_GetVal());
	Data[5] = Data[5] | (uint8_T)(fltm_enum_DsgPwrLimFct);
	Data[6] = Data[6] | (uint8_T)(fltm_enum_ChgPwrLimFct);
	Data[7] = Data[7] | (uint8_T)(fltm_enum_BackPwrLimFct);
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x17,Data,8);  //Enqueue
}

void CAN0_Send_0x6D8_Debug_CellVolInf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	static uint8_T SerialNum=0;
	Data[0] =42;//Pdcfg_BCU_CellSmpChipNum*Pdcfg_SigChipMaxSplnum;
	Data[1]= SerialNum+1;
	Data[2] =bottv_mv_cellVolt[SerialNum*3+0]/256;
	Data[3] =bottv_mv_cellVolt[SerialNum*3+0]%256;
	Data[4] =bottv_mv_cellVolt[SerialNum*3+1]/256;
	Data[5] =bottv_mv_cellVolt[SerialNum*3+1]%256;
	Data[6] =bottv_mv_cellVolt[SerialNum*3+2]/256;
	Data[7] =bottv_mv_cellVolt[SerialNum*3+2]%256;
	if(SerialNum++>12)SerialNum=0;

	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x18,Data,8);  //Enqueue
}

void CAN0_Send_0x6D9_Debug_CellTempInf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};
	static uint8_T SerialNum1=0;

	Data[0] =14;//Pdcfg_BCU_CellSmpChipNum*Pdcfg_SigChipMaxSplnum;
	Data[1]= SerialNum1+1;
	Data[2] =bottv_c_cellTemp[SerialNum1*6+0];
	Data[3] =bottv_c_cellTemp[SerialNum1*6+1];
	Data[4] =bottv_c_cellTemp[SerialNum1*6+2];
	Data[5] =bottv_c_cellTemp[SerialNum1*6+3];
	Data[6] =bottv_c_cellTemp[SerialNum1*6+4];
	Data[7] =bottv_c_cellTemp[SerialNum1*6+5];
	if(SerialNum1++>=2)SerialNum1=0;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x19,Data,8);  //Enqueue
}

void CAN0_Send_0x6DA_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(bottv_ms_sysRunTime>>24);
	Data[1]= (uint8_t)(bottv_ms_sysRunTime>>16);
	Data[2] =(uint8_t)(bottv_ms_sysRunTime>>8);
	Data[3] =(uint8_t)(bottv_ms_sysRunTime>>0);
	Data[4] =bottv_ms_InCanRFre;
	Data[5] =bottv_ms_CCanRFre;
//	Data[6] =vewm_enum_DatFlow;
//	Data[7] =bottv_ms_socFre;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1A,Data,8);  //Enqueue
}

void CAN0_Send_0x6DB_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(mc33771_k_curr>>24);
	Data[1]= (uint8_t)(mc33771_k_curr>>16);
	Data[2] =(uint8_t)(mc33771_k_curr>>8);
	Data[3] =(uint8_t)(mc33771_k_curr>>0);
	Data[4] =BatPack.u16VoltCell[1][0]/256;
	Data[5] =BatPack.u16VoltCell[1][0]%256;
	Data[6] =BatPack.u16VoltCell[2][1]/256;
	Data[7] =BatPack.u16VoltCell[2][1]%256;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1B,Data,8);  //Enqueue

}

void CAN0_Send_0x6DC_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(0>>24);
	Data[1]= (uint8_t)(0>>16);
	Data[2] =(uint8_t)(0>>8);
	Data[3] =(uint8_t)(0>>0);
	Data[4] =0;
	Data[5] =0;
	Data[6] =0;
	Data[7] =0;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1C,Data,8);  //Enqueue
}

void CAN0_Send_0x6DD_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(0>>24);
	Data[1]= (uint8_t)(0>>16);
	Data[2] =(uint8_t)(0>>8);
	Data[3] =(uint8_t)(0>>0);
	Data[4] =0;
	Data[5] =0;
	Data[6] =0;
	Data[7] =0;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1D,Data,8);  //Enqueue
}

void CAN0_Send_0x6DE_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(0>>24);
	Data[1]= (uint8_t)(0>>16);
	Data[2] =(uint8_t)(0>>8);
	Data[3] =(uint8_t)(0>>0);
	Data[4] =0;
	Data[5] =0;
	Data[6] =0;
	Data[7] =0;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1E,Data,8);  //Enqueue
}

void CAN0_Send_0x6DF_Debug_Inf(void)
{
	uint8_T Data[8]={0,0,0,0,0,0,0,0};

	Data[0] =(uint8_t)(0>>24);
	Data[1]= (uint8_t)(0>>16);
	Data[2] =(uint8_t)(0>>8);
	Data[3] =(uint8_t)(0>>0);
	Data[4] =0;
	Data[5] =0;
	Data[6] =0;
	Data[7] =0;
	VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x1F,Data,8);  //Enqueue

}

void CAN0_Send_0x6E0_Debug_Inf(void)
{
        uint8_T Data[8]={0,0,0,0,0,0,0,0};

        Data[0] =(uint8_t)(bottv_enum_chipBalanceCtrl[0]>>8);
        Data[1]= (uint8_t)(bottv_enum_chipBalanceCtrl[0]>>0);
        Data[2] =(uint8_t)(bottv_enum_chipBalanceCtrl[1]>>8);
        Data[3] =(uint8_t)(bottv_enum_chipBalanceCtrl[1]>>0);
        Data[4] =(uint8_t)(bottv_enum_chipBalanceCtrl[2]>>8);
        Data[5] =(uint8_t)(bottv_enum_chipBalanceCtrl[2]>>0);
        Data[6] =0;
        Data[7] =0;
        VCUCAN_Debug_Send_Data(CAN_0x6C0_TXID|0x20,Data,8);  //Enqueue
}

void CAN0_Send_10ms_Smp1_Debug(void)
{
	CAN0_Send_0x6C4_Debug_IOSts();
	CAN0_Send_0x6CE_Debug_SmpIg();
}

void CAN0_Send_20ms_Smp1_Debug(void)
{
	CAN0_Send_0x6C9_Debug_HVInfo();
}
void CAN0_Send_20ms_Smp2_Debug(void)
{
	CAN0_Send_0x6D3_Debug_WorkModeInfo();

}

void CAN0_Send_20ms_Smp3_Debug(void)
{
	CAN0_Send_0x6D7_Debug_FaultInfo();
}

void CAN0_Send_20ms_Smp4_Debug(void)
{
	CAN0_Send_0x6C6_Debug_SOHInfo();
}

void CAN0_Send_100ms_Smp1_Debug(void)
{
	 CAN0_Send_0x6CB_Debug_CellVoltInfo();
}
void CAN0_Send_100ms_Smp2_Debug(void)
{

	CAN0_Send_0x6CC_Debug_CellTempInfo();
}
void CAN0_Send_100ms_Smp3_Debug(void)
{
	CAN0_Send_0x6CD_Debug_SmpVolt();

}
void CAN0_Send_100ms_Smp4_Debug(void)
{
	CAN0_Send_0x6D6_Debug_InsInfo();
}
void CAN0_Send_100ms_Smp5_Debug(void)
{
	CAN0_Send_0x6D1_Debug_SOCInfo();
}

void CAN0_Send_200ms_Smp1_Debug(void)
{
	CAN0_Send_0x6D2_Debug_CurrInfo();
}

void CAN0_Send_200ms_Smp2_Debug(void)
{
	CAN0_Send_0x6D8_Debug_CellVolInf();
}

void CAN0_Send_200ms_Smp3_Debug(void)
{
	CAN0_Send_0x6D9_Debug_CellTempInf();
}

void CAN0_Send_200ms_Smp4_Debug(void)
{
	CAN0_Send_0x6C3_Debug_ExDflash();
}

void CAN0_Send_200ms_Smp5_Debug(void)
{
	CAN0_Send_0x6D4_Debug_Info();
}

void CAN0_Send_500ms_Smp1_Debug(void)
{
	CAN0_Send_0x6C7_Debug_Add();
	CAN0_Send_0x6DB_Debug_Inf();
}

void CAN0_Send_500ms_Smp2_Debug(void)
{
	CAN0_Send_0x6C5_Debug_ChgReqCurr();
	CAN0_Send_0x6DC_Debug_Inf();
}
void CAN0_Send_500ms_Smp3_Debug(void)
{
	CAN0_Send_0x6DA_Debug_Inf();
	CAN0_Send_0x6DD_Debug_Inf();
}
void CAN0_Send_500ms_Smp4_Debug(void)
{
	CAN0_Send_0x6C2_Debug_HVPara();
	CAN0_Send_0x6DE_Debug_Inf();
}
void CAN0_Send_500ms_Smp5_Debug(void)
{
	CAN0_Send_0x6D0_Debug_RTC();
	CAN0_Send_0x6DF_Debug_Inf();
}

//////////////////////////Cycle Manager Function///////////////////////
CanMsgType DebugMsg[VcanMsgDebugMax] =
{
	{CAN0_Send_10ms_Smp1_Debug,10,0,0},

	{CAN0_Send_20ms_Smp1_Debug,20,0,0},
	{CAN0_Send_20ms_Smp2_Debug,20,0,0},
	{CAN0_Send_20ms_Smp3_Debug,100,0,0},
	{CAN0_Send_20ms_Smp4_Debug,20,0,0},

	{CAN0_Send_100ms_Smp1_Debug,100,0,0},
	{CAN0_Send_100ms_Smp2_Debug,100,0,0},
	{CAN0_Send_100ms_Smp3_Debug,1000,0,0},
	{CAN0_Send_100ms_Smp4_Debug,100,0,0},
	{CAN0_Send_100ms_Smp5_Debug,100,0,0},

	{CAN0_Send_200ms_Smp1_Debug,200,0,0},
	{CAN0_Send_200ms_Smp2_Debug,200,0,0},
	{CAN0_Send_200ms_Smp3_Debug,200,0,0},
	{CAN0_Send_200ms_Smp4_Debug,200,0,0},
	{CAN0_Send_200ms_Smp5_Debug,200,0,0},

	{CAN0_Send_500ms_Smp1_Debug,500,0,0},
	{CAN0_Send_500ms_Smp2_Debug,500,0,0},
	{CAN0_Send_500ms_Smp3_Debug,500,0,0},
	{CAN0_Send_500ms_Smp4_Debug,500,0,0},
	{CAN0_Send_500ms_Smp5_Debug,500,0,0}
};

void Task_DebugAutoSend(uint16_T cycle)
{
	uint16_T current_time = 0;
	uint8_T k;
	static uint16_T Time_Cnt = 0;

    if(bottv_flg_debug!=1)
        return;

	Time_Cnt ++;
	current_time = Time_Cnt*cycle; //当前时间

	for(k = 0 ; k < VcanMsgDebugMax ; k ++)
	{
		if(*(DebugMsg[k].Caller) != NULL)
		{
			if(DebugMsg[k].Used == 0)
			{
				(*DebugMsg[k].Caller)();
				DebugMsg[k].Used = 1;
				DebugMsg[k].Timestamp = current_time;
				break;
			}
			else if(current_time >= (DebugMsg[k].Cyc + DebugMsg[k].Timestamp))
			{
				(*DebugMsg[k].Caller)();
				DebugMsg[k].Timestamp = current_time;
				break;
			}
			else
			{
					;
			}
		}
	}

	if(current_time >= 60000)
	{
		Time_Cnt = 0;
		for(k = 0 ; k < VcanMsgDebugMax ;k ++ )
		{
			DebugMsg[k].Used = 0;
			DebugMsg[k].Timestamp = 0;
		}
	}
}

/*******************************************************************************
**函数名称：Task_DebugReqTrans
**功    能：报文发送
**参    数：
**返 回 值：
**备    注：
*******************************************************************************/
void Task_DebugReqTrans(uint16_T cycle)
{
    static uint16_t debug1000ms=0;

	if(++debug1000ms>=(100/cycle))
		debug1000ms=0;

	if(debug1000ms%4==0U)
		CAN0_Send_0x6CA_Debug_Ver();

	if(debug1000ms%16==0U)
		CAN0_Send_0x6C8_Debug_Soh();
}





